package com.company.project.task;

import com.company.project.websocket.PayWebSocket;
import com.company.project.dao.OrderMainMapper;
import org.springframework.beans.factory.annotation.Autowired;

public class CheckOrderPay implements Runnable {
    @Autowired
    private OrderMainMapper orderMainMapper;

    private boolean stopMe = true;
    public void stopMe() {
        stopMe = false;
    }

    @Override
    public void run()  {
        PayWebSocket wbs=new PayWebSocket();
        Integer payOldNum = orderMainMapper.selectPayCount();
        Integer finOldNum = orderMainMapper.selectFinishCount();
        while(stopMe) {
            // 此处进行业务逻辑
            Integer payNewNum = orderMainMapper.selectPayCount();
            Integer finNewNum = orderMainMapper.selectFinishCount();
            if(payNewNum != payOldNum && finOldNum != finNewNum) {
                if(payOldNum - payNewNum == finNewNum - finOldNum){
                    wbs.onMessage("支付成功");
                }
            }
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
